import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Solution1104 {

    int[] pow=new int[]{1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576};

    public List<Integer> pathInZigZagTree(int label) {
        int t=label;
        int temp=2,c=1;
        while (label>=temp){
            temp*=2;
            c++;
        }
        List<Integer> ans=new ArrayList<>();
        if (c%2==0){
            t=pow[c]-t+pow[c-1]-1;
        }
        while (t!=0){
            ans.add(t);
            t=t/2;
        }
        Collections.reverse(ans);
        for (int i=1;i<ans.size();i+=2){
            ans.set(i,pow[i+1]-ans.get(i)+pow[i]-1);
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1104().pathInZigZagTree(14));
    }
}
